package com.wish.g01.base.service.impl;

import com.alibaba.fastjson.JSON;
import com.wish.g01.base.dto.CheckBatchType;
import com.wish.g01.base.dto.CheckBillBatchRequestDto;
import com.wish.g01.base.dto.CwCheckBatchDto;
import com.wish.g01.base.entity.CwCheckBatch;
import com.wish.g01.base.mapper.CwCheckBatchMapper;
import com.wish.g01.base.service.ICwCheckBatchService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Service;

import javax.xml.transform.Source;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 对账批次表 服务实现类
 * </p>
 *
 * @author hao
 * @since 2022-05-24
 */
@Service
public class CwCheckBatchServiceImpl extends ServiceImpl<CwCheckBatchMapper, CwCheckBatch> implements ICwCheckBatchService {

    @Override
    public List<CwCheckBatch> listAll(CwCheckBatchDto dto) {
        return getBaseMapper().listAll(dto);
    }

    /*@Override
    public void checkBillBatch(CheckBillBatchRequestDto checkBillBatchRequestDto) {
        System.out.println("checkBillBatch对账处理 Start");
        if (checkBillBatchRequestDto.getCheckBatchType() == CheckBatchType.EIGHT.getIndex()) {
            // 8:30 实时代付和快捷
            System.out.println("代付和快捷对账开始");
            // 2、生成相应对账批次，及进行对账处理生成对应的批次明细
            // 代付
            CwCheckBatch checkBatchInfo = this.createCheckBatchNo(
                    BillTypeEnum.DF.getIndex(),
                    CheckBatchType.EIGHT.getIndex(),
                    billDay,
                    downloadBatchDf);
            this.doCheckBill(checkBatchInfo);
            System.out.println("代付对账完成");
            // 快捷
            checkBatchInfo = this.createCheckBatchNo(
                    BillTypeEnum.KJ.getIndex(),
                    checkBillBatchRequestDto.getLoginUserId(),
                    CheckBatchType.EIGHT.getIndex(),
                    billDay,
                    downloadBatchKj);
            this.doCheckBill(checkBatchInfo);
            System.out.println("快捷对账完成");

        } else if (checkBillBatchRequestDto.getCheckBatchType() == CheckBatchType.ELEVEN.getIndex()) {
            // 11:00微信和支付宝
            System.out.println("微信支付宝开始对账");
            // 微信
            CwCheckBatch checkBatchInfo = this.createCheckBatchNo(
                    BillTypeEnum.WX.getIndex(),
                    checkBillBatchRequestDto.getLoginUserId(),
                    CheckBatchType.ELEVEN.getIndex(),
                    billDay,
                    downloadBatchWx);
            this.doCheckBill(checkBatchInfo);
            System.out.println("微信对账完成");

            // 支付宝
            checkBatchInfo = this.createCheckBatchNo(
                    BillTypeEnum.AL.getIndex(),
                    checkBillBatchRequestDto.getLoginUserId(),
                    CheckBatchTypeEnum.ELEVEN.getIndex(),
                    billDay,
                    downloadBatchZfb);
            this.doCheckBill(checkBatchInfo);
            System.out.println("支付宝对账完成");

        } else if (checkBillBatchRequestDto.getCheckBatchType() == CheckBatchType.SD.getIndex()) {
            // 手动执行的时候
            System.out.println("手动执行对账开始");
            // 手动对账的时候，账期年月日根据选择的批次来取得
            // 1、查询旧批次信息
            CwCheckBatch oldBatch = this.selectCheckBatchByBatchNo(checkBillBatchRequestDto.getBatchNo());

            if(oldBatch == null) {
                System.out.println("旧批次查询结果无");
                return;
            }

            // 旧批次状态check
            // 取消状态和对账确认状态，不允许重新对账
            if (BusinessCompleteState.QUXIAO.getIndex() == oldBatch.getCompleteState()) {
                System.out.println("指定旧批次已经被取消，不能进行对账处理");
                return;
            }
            if (oldBatch.getConfirmDate() != null) {
                System.out.println("指定批次已经对账确认，不能进行对账处理");
                return;
            }
            // 3、生成相应对账批次，及进行对账处理生成对应的批次明细
            CwCheckBatch checkBatchInfo = this.createCheckBatchNo(
                    oldBatch.getBillType(),
                    checkBillBatchRequestDto.getLoginUserId(),
                    CheckBatchTypeEnum.SD.getIndex(),
                    oldBatch.getBillDay(),
                    downloadBatch);
            this.doCheckBill(checkBatchInfo);
            System.out.println("重新对账完成");
            // 4、手动重新对账的时候，将旧批次取消，包括批次明细
            this.cancleCheckBatchById(oldBatch);
            System.out.println("旧批次取消处理完成");
            System.out.println("手动对账完成");
        }
        System.out.println("checkBillBatch对账处理 End.");
    }

    private CwCheckBatch selectCheckBatchByBatchNo(String batchNo) {
        System.out.println("开始selectCheckBatchByBatchNo处理");
        CwCheckBatch selectOption = new CwCheckBatch();
        selectOption.setBatchNo(batchNo);
        selectOption.setDelFlg(false);
        EntityWrapper<CwCheckBatch> selectWrapper = new EntityWrapper<CwCheckBatch>(selectOption);
        CwCheckBatch result =  this.selectOne(selectWrapper);
        System.out.println("结束selectCheckBatchByBatchNo处理");

        return result;
    }
    private void doCheckBill(CwCheckBatch checkBatchInfo) {
    }

    private void cancleCheckBatchById(CwCheckBatch oldBatch) {
    }*/
}
